<template>
  <div>
    <div>
      <ordersearch @search="search" />
    </div>
    <div>
      <Table
        ref="selection"
        stripe
        border
        :loading="loading"
        :columns="columns1"
        :data="data1"
        height="800"
        @on-select="select"
      ></Table>
    </div>
    <upstate :oid="state" :show="s1" @change1="c1" @change2="c2" />
  </div>
</template>
<script>
import ordersearch from "./saleform/order_search.vue";
import upstate from "./saleform/upstate.vue";
export default {
  data() {
    return {
      loading: true,
      state: {},
      s1: false,
      columns1: [
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          title: "订单号",
          key: "oid",
          align: "center",
        },
        {
          title: "顾客",
          key: "cname",
          align: "center",
        },
        {
          title: "支付时间",
          key: "paytime",
          align: "center",
        },
        {
          title: "发货时间",
          key: "sendtime",
          align: "center",
          sortable: true
        },
        {
          title: "支付方式",
          key: "payway",
          align: "center",
          filters: [
            {
              label: "现金",
              value: "现金",
            },
            {
              label: "转账",
              value: "转账",
            },
            {
              label: "支票",
              value: "支票",
            },
          ],
          filterMethod(value, row) {
            return row.payway.indexOf(value) > -1;
          },
        },
        {
          title: "仓库名",
          key: "sname",
          align: "center",
        },
        {
          title: "作物名",
          key: "cropname",
          align: "center",
        },
        {
          title: "批次",
          key: "batch",
          align: "center",
        },
        {
          title: "数量",
          key: "num",
          align: "center",
          sortable: true
        },
        {
          title: "单价",
          key: "price",
          align: "center",
        },
        {
          title: "总额",
          key: "tq",
          align: "center",
          sortable: true
        },
      ],
      data1: [],
    };
  },
  mounted() {
    this.axios
      .get("/api/orders")
      .then((r) => {
        this.data1 = r.data;
        this.loading = false;
      })
      .catch((e) => {
        this.$Message.error("e" + e);
        this.loading = false;
      });
  },
  methods: {
    select(_, r) {
      // this.$Message.info(r.oid);
      this.s1 = true;
      this.state = r.oid;
    },
    c1(value) {
      this.s1 = value;
      this.$refs.selection.selectAll(value);
    },
    c2(value) {
      this.s1 = value;
      this.$refs.selection.selectAll(value);
    },
    search(data) {
      if (data.oid || data.cname || data.batch || data.sname || data.cropname) {
        this.loading = true;
        this.axios
          .get("/api/orders", { params: { param: data } })
          .then((r) => {
            this.data1 = r.data;
            this.loading = false;
          })
          .catch((e) => {
            this.$Message.error("e" + e);
            this.loading = false;
          });
      } else {
        this.$Message.error("不能搜索空值");
      }
    },
  },
  components: {
    ordersearch,
    upstate,
  },
};
</script>
